<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }
        
        #ab {
            width: 300px;
            height: 200px;
            background-color: aqua;
            position: fixed;
            right: 0;
            bottom: 0;
            /* display: none; */
        }
        
        #close {
            float: right;
            width: 24px;
            height: 24px;
            background-color: burlywood;
            color: chartreuse;
            line-height: 24px;
            text-align: center;
        }
    </style>
</head>

<body>
    <div id="ab">
        <span id="close">X</span>
        <p>
            <span id="time">10</span>
            <span>S后自动关闭</span>
        </p>
    </div>
    <script>
        var oab = document.getElementById("ab");
        var otime = document.getElementById("time");
        var oclose = document.getElementById("close");

        // 倒计时
        var t = setInterval(function() {
            otime.innerHTML--;
            if (otime.innerHTML <= 0) {
                oab.style.display = "none";
            }
            setTimeout(function() {
                oab.style.display = "block";
            }, 200);
        }, 500);

        // 点击关闭
        oclose.onclick = function() {
            oab.style.display = "none";
            setTimeout(function() {
                oab.style.display = "block";
            }, 200);
        };
    </script>
</body>

</html>